﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Teein.Proxy.Bot.Model;
using MongoDB.Driver;

namespace Teein.Proxy.Bot.DAL
{
    public class AccountDAL:IDAL<AccountInfo>
    {
        public bool Insert(AccountInfo model)
        {
            return SQLHelper.Insert<AccountInfo>(model);
        }

        public bool Update(AccountInfo model)
        {
            UpdateDocument ud = new UpdateDocument();
            ud.Add("AccountName", model.AccountName);
            ud.Add("AccessToken", model.AccessToken);
            ud.Add("AuthorizeTime", model.AuthorizeTime);
            ud.Add("Expires", model.Expires);
            ud.Add("LastTime", model.LastTime);
            return SQLHelper.Update<AccountInfo>(new QueryDocument("_id", model.PID), ud);
        }

        public bool Delete(AccountInfo model)
        {
            return SQLHelper.Delete<AccountInfo>(new QueryDocument("_id", model.PID));
        }

        public bool Delete(MongoDB.Driver.IMongoQuery mq)
        {
            return SQLHelper.Delete<AccountInfo>(mq);
        }

        public AccountInfo FindOne(MongoDB.Driver.IMongoQuery mq)
        {
            return SQLHelper.FindOne<AccountInfo>(mq);
        }

        public IList<AccountInfo> Find(MongoDB.Driver.IMongoQuery mq)
        {
            return SQLHelper.Find<AccountInfo>(mq);
        }
    }
}
